package com.ulife.song.manager.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.ulife.common.Result;
import com.ulife.common.exception.ManagerException;
import com.ulife.song.dao.SongDao;
import com.ulife.song.dao.dataobject.SongDO;
import com.ulife.song.manager.SongManager;

public class SongManagerImpl implements SongManager {
	
	@Autowired
	private SongDao songDao;

	public List<SongDO> getAllSong() throws ManagerException {
		try {
			return songDao.getAllSong();
		} catch (SQLException e) {
			throw new ManagerException(e);
		}
	}

	public Result<SongDO> addSong(SongDO song) throws ManagerException {
		Result<SongDO> result = new Result<SongDO>();
		try {
			int id = songDao.addSong(song);
			if (id > 0) {
				result.setSuccess(true);
				result.setModule(song);
			}
			return result;
		} catch (SQLException e) {
			throw new ManagerException(e);
		}
	}

	public Result<SongDO> getSongById(long songId) throws ManagerException {
		Result<SongDO> result = new Result<SongDO>();
		try {
			SongDO song = songDao.getSongById(songId);
			if (song != null) {
				result.setSuccess(true);
				result.setModule(song);
			}
			return result;
		} catch (SQLException e) {
			throw new ManagerException(e);
		}
	}

	public Result<Integer> updateSong(SongDO song) throws ManagerException {
		Result<Integer> result = new Result<Integer>();
		try {
			int i = songDao.updateSong(song);
			if (i > 0) {
				result.setSuccess(true);
			}
			return result;
		} catch (SQLException e) {
			throw new ManagerException(e);
		}
	}

	public List<SongDO> querySong(SongDO songDO) throws ManagerException {
		try {
			return songDao.querySong(songDO);
		} catch (SQLException e) {
			throw new ManagerException(e);
		}
	}

}
